<?php

namespace App\Console\Commands;

use App\Models\kly\Kly_camp;
use Illuminate\Console\Command;
use DB;
use App\Models\Squad;
use App\Models\Crouse;
use App\Models\Classroom;
use App\Models\Notice;


class kly_report extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'kly_report';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $squads = Kly_camp::where('camp_type','2')->get()->toArray();

        foreach($squads as $v){
            $students = DB::table('kly_students')->where('small_camp_id',$v['id'])->get();
            $temp = array();
            $temp['pid'] = 0;
            $temp['name'] = $v['name'].'-日报/'.date('Y-m-d');
            $temp['small_camp'] = $v['id'];
            $temp['student'] = 0;
            $temp['type'] = '1';
            $temp['start_time'] = date('Y-m-d');
            $temp['end_time'] = date('Y-m-d');

            $id = DB::table('kly_reports')->insertGetId($temp);
            $insert = array();
            foreach($students as $_v){
                $insert[] = array(
                    'pid'=>$id,
                    'student'=>$_v->student_id,
                    'small_camp'=>$v['id']
                );
            }
            DB::table('kly_reports')->insert($insert);
        }
    }
}
